/*
 An instance of this class includes the behavior interpretation made
for a particular object by each normality component.
*/
import java.util.Vector;


class ObjectAnalysis{
    protected String id_obj;
    protected int current_frame;
    protected Vector<ComponentOutPut> v_components_values;
    protected float global_degree;
    protected Vector<FuzzySetGA> v_sets; //fuzzy set that represent the different normality intervals.
    protected Vector<Float> v_membership_intervals; //mebership values to the normality intervals
        
    public ObjectAnalysis(String id, int current_frame){
	this.id_obj = id;
	this.current_frame = current_frame;
	v_components_values = new Vector();
	this.global_degree = 1;
	//creating v_sets
	v_sets = new Vector();
	v_sets.addElement(new FuzzySetGA("absolutely abnormal", new Float(0), new Float(0), new Float(0.1), new Float(0.2)));
	v_sets.addElement(new FuzzySetGA("possibly abnormal", new Float(0.1), new Float(0.2), new Float(0.3), new Float(0.4)));
	v_sets.addElement(new FuzzySetGA("suspicius", new Float(0.3), new Float(0.4), new Float(0.5), new Float(0.6)));
	v_sets.addElement(new FuzzySetGA("possibly normal", new Float(0.5), new Float(0.6), new Float(0.7), new Float(0.8)));
	v_sets.addElement(new FuzzySetGA("absolutely normal", new Float(0.7), new Float(0.8), new Float(1), new Float(1)));
	v_membership_intervals = new Vector();
    }
    
    public float getMembershipIntervalAt(int pos){
	return this.v_membership_intervals.elementAt(pos);
    }
    public float getGlobalDegree(){return this.global_degree;}
    public float normalityComponent(int index){
	ComponentOutPut cop = v_components_values.elementAt(index);
	return cop.degree;
    }

    public void addComponentValue(ComponentOutPut cop){
	this.v_components_values.addElement(cop);
    }

    public void calculateGlobalDegree(){
	OWA operator = new OWA();
	//this method must be updated if new component are included.
	//Currently, all componets have the same weight.
	operator.addWeight(new Float(0.8));
	operator.addWeight(new Float(0.2));
	operator.addValue((this.v_components_values.elementAt(0)).degree);
	operator.addValue((this.v_components_values.elementAt(1)).degree);
	this.global_degree = operator.calculateValue();
	updateMembershipIntervals();
    }//end method

    private void updateMembershipIntervals(){
	//update the membership value to the normality intervals
	for(int i=0; i < this.v_sets.size(); i ++){
	    FuzzySetGA set = v_sets.elementAt(i);
	    this.v_membership_intervals.addElement(set.membershipValue(this.global_degree));	    
	}//end for
    }//end method

}//end Class
